import store from "../store"
import Cookies from "js-cookie"
const Tools = {
    loads: {},
    showLoading: (loading_message) => {
        loading_message = loading_message || "努力加载中..."
        store.commit("SHOW_LOADING", loading_message)
    },
    hideLoading() {
        store.commit("HIDE_LOADING")
    },
    setCookie(name, value) {
        try{
            value = JSON.stringify(value)
        }catch(e){
            // console.error(e)
        }
        Cookies.set(name, value);
    },
    getCookie(name) {
        let value = Cookies.get(name)
        try{
            value = JSON.parse(value)
        }catch(e){
            // console.error(e)
        }
        return value
    },
    removeCookie(name) {
        if(!name) return;
        Cookies.remove(name);
    }
}

export default Tools;